package com.blog.back.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.blog.vo.ArticleClassificationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.blog.entity.ClassificationEntity;
import com.blog.back.service.ClassificationService;
import com.blog.utils.PageUtils;
import com.blog.utils.R;



/**
 * 
 *
 * @author codedorado
 * @email codedorado@foxmail.com
 * @date 2020-08-15 15:26:05
 */
@RestController
@RequestMapping("back/classification")
public class ClassificationController {
    @Autowired
    private ClassificationService classificationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    // @RequiresPermissions("back:classification:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = classificationService.queryPage(params);

        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{classId}")
    // @RequiresPermissions("back:classification:info")
    public R info(@PathVariable("classId") Long classId){
		ClassificationEntity classification = classificationService.getById(classId);

        return R.ok().put("data", classification);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("back:classification:save")
    public R save(@RequestBody ClassificationEntity classification){
		classificationService.save(classification);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("back:classification:update")
    public R update(@RequestBody ClassificationEntity classification){
		classificationService.updateById(classification);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    // @RequiresPermissions("back:classification:delete")
    public R delete(@RequestBody Long[] classIds){
		classificationService.removeByIds(Arrays.asList(classIds));

        return R.ok();
    }

    @RequestMapping("/listArticleAndClass/{usersId}")
    public R listArticleAndClassById(@PathVariable("usersId") Long usersId){
        List<ArticleClassificationVO> list = classificationService.findClassAndArticleByUsersId(usersId);

        return R.ok().put("data", list);
    }

}
